package cur.nature.domain.common.config;

import cur.nature.tinyorm.core.template.DefaultJdbcTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Configuration
@ConditionalOnProperty( value = {"cur.component.domain.enable"})
public class DBDomainConfig {
    public final static String DATASOURCE = "curCompDomainDataSource";
    public final static String TEMPLATE = "curCompDomainTemplate";

    @Bean(name = DATASOURCE)
    @DependsOn(DefaultJdbcTemplate.DATASOURCE)
    @Primary
//    @ConfigurationProperties(prefix = "cur.component.quartz.datasource")
    public DataSource dataSource(@Qualifier(DefaultJdbcTemplate.DATASOURCE) DataSource dataSource) {
        return dataSource;
    }

    @Bean(name = TEMPLATE)
    @DependsOn(DefaultJdbcTemplate.TEMPLATE)
    @Primary
    public DefaultJdbcTemplate curQuantTemplate(@Qualifier(DefaultJdbcTemplate.TEMPLATE) DefaultJdbcTemplate template) {
        return template;
    }
}
